package main

func main() {
	println()
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func findTilt(root *TreeNode) (res int) {
	var back func(root *TreeNode) int
	back = func(node *TreeNode) int {
		if node == nil {
			return 0
		}

		leftSum := back(node.Left)
		rightSum := back(node.Right)
		res += abs(leftSum - rightSum)
		return leftSum + rightSum + node.Val

	}
	back(root)
	return
}

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}
